{template 'header'}
    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-default">

                <div class="panel-body">
                    <form action="{php echo webUrl('user/user/add')}" method="post" enctype="multipart/form-data" class="form-horizontal ">
                        <div class="form-group">
                            <label class="col-md-2 control-label" for="text-input">操作员用户名 </label>
                            <div class="col-md-8">
                                <input type="text" id="text-input" name="username" class="form-control" value="{$item['username']}" placeholder="" autocomplete="false">
                                <span class="help-block">不能输入 系统现有用户! 只能新增 权限才能生效. 新增的从这里可以修改</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label" for="text-input">操作员密码 </label>
                            <div class="col-md-8">
                                <input type="password"  name="password" class="form-control"   autocomplete="false"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label" for="text-input">所属角色 </label>
                            <div class="col-md-8">
                                 <span class="input-group-selectn">
                                      <select name="roleid" class="form-control" onchange="changeRole(event)">
                                          <option value="0">无角色</option>
                                          {loop $roles $v}
                                          <option value="{$v['id']}" {if $v['id'] == $item['roleid']}selected = "selected"{/if}>{$v['rolename']}</option>
                                          {/loop}
                                      </select>
                                 </span>
                                <span class="help-block">如果您选择了角色，则此用户本身就继承了此角色的所有权限</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label" for="text-input">操作员姓名 </label>
                            <div class="col-md-8">
                                <input type="text" name="realname"  value="{$item['realname']}" class="form-control" placeholder="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label" for="text-input">操作员电话 </label>
                            <div class="col-md-8">
                                <input type="text"  name="mobile" value="{$item['mobile']}" class="form-control" placeholder="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label" >操作员状态 </label>
                            <div style="padding-top: 7px" class="col-md-8">
                                <label class="switch switch-primary">
                                    <input type="checkbox" name="status" value="1" class="switch-input" checked>
                                    <span class="switch-label" data-on="On" data-off="Off"></span>
                                    <span class="switch-handle"></span>
                                </label>
                            </div>
                        </div>
                        {template 'permission'}
                        <br>
                </div>
                <div class="panel-footer"  >
                    <input type="hidden" name="id"  value="{$_GPC['id']}" >
                    <button type="submit" class="btn btn-sm btn-success"><i class="fa fa-dot-circle-o"></i> 保存</button>
                    <button type="reset" class="btn btn-sm btn-danger"><i class="fa fa-ban"></i> 撤销</button>
                </div>
                </form>
                <script language='javascript'>
                    function changeRole(e) {
                        select_role(e.target.value)
                    }
                    function select_role(id) {
                        $.ajax({url:"{php echo webUrl('user/role/query')}",data:{id:id},success:function(result){
                                $("#userid").val(result.id);
                                $("#user").val( result.rolename );
                                var perms = JSON.parse(result).perms2.split(',');
                                $(':checkbox').not(':eq(0)').removeAttr('disabled').removeAttr('checked').each(function(){

                                    var _this = $(this);
                                    var perm = '';
                                    if( _this.data('group') ){
                                        perm+=_this.data('group');
                                    }
                                    if( _this.data('parent') ){
                                        if (_this.data('parent') != 'text') {
                                            perm += "." + _this.data('parent');
                                        }
                                    }
                                    if( _this.data('son') ){
                                        if (_this.data('son') != 'text') {
                                            perm += "." + _this.data('son');
                                        }
                                    }
                                    if( _this.data('grandson') ){
                                        if (_this.data('grandson') != 'text') {
                                            perm += "." + _this.data('grandson');
                                        }
                                    }
                                    if( $.arrayIndexOf(perms,perm)!=-1){
                                        $(this).attr('disabled',true).get(0).checked =true;
                                    }
                                });
                                $(".close").click();
                            }});
                    }
                </script>
            </div>

            </div>
    </div><!--/.row-->
        <!-- end: Content -->
{template 'footer'}